const StoreJS = require('store/dist/store.legacy');
export default {
  state: {
    sideBarIndex: StoreJS.get('dx_op_sideBarIndex') || '/',
    data: [
      //sidebar
      {
        authUrl: '1231',
        authName: '数据查询',
        authNameEn: 'Anchor Management',
        iconfont: 'iconfont icon-shujuchaxun',
        authUrlStatus: false,
        tblMerchantResource: [
          {
            authUrl: '/',
            authName: '主控台',
            authNameEn: 'Anchor Management',
            authUrlStatus: false
          },
          {
            authUrl: '/datalist',
            authName: '数据列表',
            authNameEn: 'Anchor Management',
            authUrlStatus: false
          },
          {
            authUrl: '/MonitoringData',
            authName: '监控数据',
            authNameEn: 'Anchor Management',
            authUrlStatus: false
          },
          {
            authUrl: '/MapData',
            authName: '地图数据',
            authNameEn: 'Anchor Management',
            authUrlStatus: false
          },
          {
            authUrl: '/Animejs',
            authName: '动画anime',
            authNameEn: 'Anchor Management',
            authUrlStatus: false
          },
        ]
      },
      {
        authUrl: 'vueEdit',
        authName: '系统设置',
        authNameEn: 'Video Management',
        iconfont: 'iconfont icon-shezhi',
        authUrlStatus: false,
        tblMerchantResource: [
          {
            authUrl: '/setting',
            authName: '设置',
            authNameEn: 'Anchor Management',
            authUrlStatus: false
          },
        ]
      }
    ],
    tabsList: StoreJS.get('tabsList') ? StoreJS.get('tabsList') : []
  },
  mutations: {
    // 初始化sideBarIndex
    initSidebar(state) {
      state.sideBarIndex = state['data'][0].tblMerchantResource[0]['authUrl'];
      StoreJS.set('dx_op_sideBarIndex', state.sideBarIndex);
    },
    INIT_TABLES(state){
      state.tabsList=[]
      state.tabsList.push(state['data'][0].tblMerchantResource[0]);
      StoreJS.set('tabsList', state.tabsList);
    },
    //设置sideBarIndex
    setSidebar(state, indexPath) {
      if (indexPath[1]) {
        state.sideBarIndex = indexPath[1];
      } else {
        state.sideBarIndex = indexPath[0];
      }
      StoreJS.set('dx_op_sideBarIndex', state.sideBarIndex);
    },
    SET_BAR(state,indexPath){
      state.sideBarIndex= indexPath
      StoreJS.set('dx_op_sideBarIndex', state.sideBarIndex);
    },
    SET_TABSLSIT(state, data) {
      state.tabsList.push(data);
      StoreJS.set('tabsList', state.tabsList);
    },
    REMOVE_TABSLSIT(state, data){
      state.tabsList.splice(data,1)
      /*如果删除tabs为当前选中的tab，如果是末尾tabs则为续跳转上一级tabs，如果删除的为首位tab
      *则为第二位tabs
      */ 
      StoreJS.set('tabsList', state.tabsList);
      
    }
  }
};
